package cn.sms.pet.service.impl;

import cn.sms.basic.util.PageList;
import cn.sms.pet.domain.Pet;
import cn.sms.pet.domain.PetDetail;
import cn.sms.pet.mapper.PetDetailMapper;
import cn.sms.pet.mapper.PetMapper;
import cn.sms.basic.service.impl.BaseServiceImpl;
import cn.sms.pet.query.PetQuery;
import cn.sms.pet.service.IPetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class PetServiceImpl  extends BaseServiceImpl<Pet> implements IPetService {

    @Autowired
    private PetMapper petMapper;
    @Autowired
    private PetDetailMapper petDetailMapper;

    @Override
    public void add(Pet pet) {
        petMapper.save(pet);
        PetDetail detail = pet.getDetail();
        if(detail != null){
            detail.setPet_id(pet.getId());
            petDetailMapper.save(detail);
        }
    }

    @Override
    public void onsale(List<Long> ids) {
        Map map = new HashMap<>();
        map.put("ids", ids);
        petMapper.onsale(map);
    }

    @Override
    public void offSale(List<Long> ids) {
        Map map = new HashMap<>();
        map.put("ids", ids);
        petMapper.offSale(map);
    }

    @Override
    public Pet queryByIdDetail(Long petId) {
        Pet pet = petMapper.loadByIdDetail(petId);
        return pet;
    }

    @Override
    public void adopt(Long id) {
        petMapper.updateState(id);
    }


}
